Find Perimeter of a Rectangle

Theory:

The perimeter of a rectangle is calculated by adding the lengths of all its sides. For a rectangle, where length is denoted by L and width by W, the perimeter is given by 2 * (L + W).

Python Code:

def calculate_rectangle_perimeter(length, width):
    return 2 * (length + width)

# Taking input for the length and width of the rectangle and calculating its perimeter
def calculate_and_display_rectangle_perimeter():
    length = float(input("Enter the length of the rectangle: "))
    width = float(input("Enter the width of the rectangle: "))
    perimeter = calculate_rectangle_perimeter(length, width)
    print("Perimeter of the rectangle:", perimeter)

calculate_and_display_rectangle_perimeter()

Example Output 1:

Enter the length of the rectangle: 5

Enter the width of the rectangle: 3

Perimeter of the rectangle: 16.0

Example Output 2:

Enter the length of the rectangle: 7.5

Enter the width of the rectangle: 4.2

Perimeter of the rectangle: 23.4

Code Explanation:

The function calculate_rectangle_perimeter(length, width) calculates the perimeter of a rectangle using the formula 2 * (length + width).

The function calculate_and_display_rectangle_perimeter() takes input for the length and width of the rectangle, calculates its perimeter using the aforementioned function, and displays the result.